package com.ilink.groundservice.service.impl.dataset;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ilink.groundservice.entity.PO.dataset.DatasetIntroduction;
import com.ilink.groundservice.service.dataset.DatasetIntroductionService;
import com.ilink.groundservice.mapper.dataset.DatasetIntroductionMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
* @author ZhangBo
* @description 针对表【dataset_introduction】的数据库操作Service实现
* @createDate 2024-09-16 17:48:27
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class DatasetIntroductionServiceImpl extends ServiceImpl<DatasetIntroductionMapper, DatasetIntroduction>
    implements DatasetIntroductionService{
    private final DatasetIntroductionMapper datasetIntroductionMapper;

    /**
     * @Author ZhangBo
     * @Description 查询指定数据集介绍
     * @Date 18:19 2024/9/16
     * @Param [targetId]
     * @return com.ilink.groundservice.entity.PO.dataset.DatasetIntroduction
     **/
    @Override
    public DatasetIntroduction getDatasetsIntroduction(String targetId){
        try {
            // 将 targetId 转换为 Long 类型，确保类型匹配
            Long datasetId = Long.parseLong(targetId);

            LambdaQueryWrapper<DatasetIntroduction> instructionWrapper = new LambdaQueryWrapper<>();
            // 使用 Lambda 表达式查询 datasetId 等于 targetId 的记录，并限制返回一条记录
            instructionWrapper.eq(DatasetIntroduction::getDatasetId, datasetId).last("limit 1");

            // 查询并返回单个结果
            return datasetIntroductionMapper.selectOne(instructionWrapper);

        } catch (NumberFormatException e) {
            log.error("数据集ID格式错误: " + targetId, e);
            return null;
        } catch (Exception e) {
            log.error("函数getDatasetsIntroduction报错: " + e.getMessage(), e);
            return null;
        }
    }
}




